package br.com.hotstar.util;

import java.util.Locale;

import javax.enterprise.context.RequestScoped;

import br.com.hotstar.model.base.Base;
import br.com.hotstar.resource.annotation.Bundle;

@RequestScoped
public class ResourceBundle<T extends Base>{
	
	private java.util.ResourceBundle bundle;
	private Locale locale; 

	public ResourceBundle(Class<T> classe){
		String res = null;
		if(classe.isAnnotationPresent(Bundle.class)){
			Bundle bundle = classe.getAnnotation(Bundle.class);
			
			res = bundle.resource();
			res += "." + bundle.name();
			
		}else{
			
			bundle = java.util.ResourceBundle.getBundle("br.com.hotstar.resource.util.resourceBundle.message", locale);
			throw new ResourceBundleException(bundle.getString("msgAnotacao") + classe.getName());
			
		}
		
		bundle = java.util.ResourceBundle.getBundle(res, locale);
	}
	
	public String getString(String key){
		return bundle.getString(key);
	}

	public Locale getLocale() {
		return locale;
	}

	public void setLocale(Locale locale) {
		this.locale = locale;
	}
	
	

}
